package com.xiaohong.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.goods.dao.SpecParamMapper;
import com.xiaohong.goods.pojo.SpecParam;
import com.xiaohong.goods.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecParamServiceImpl implements SpecParamService {

    @Autowired
    private SpecParamMapper specParamMapper;


    /**
     * 条件+分页查询SpecParam
     * @param specParam 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<SpecParam> findPage(SpecParam specParam, int page, int size){
        // 构建查询条件
        QueryWrapper<SpecParam> queryWrapper = new QueryWrapper<SpecParam>(specParam);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return specParamMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询SpecParam
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<SpecParam> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return specParamMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法SpecParam
     * @param specParam
     * @return
     */
    @Override
    public List<SpecParam> findList(SpecParam specParam){
        // 构建查询条件
        QueryWrapper<SpecParam> queryWrapper = new QueryWrapper<SpecParam>(specParam);
        // 查询数据
        return specParamMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除SpecParam
     * @param id
     */
    @Override
    public void delete(Integer id){
        specParamMapper.deleteById(id);
    }

    /**
     * 根据ID修改SpecParam
     * @param specParam
     */
    @Override
    public void update(SpecParam specParam){
        specParamMapper.updateById(specParam);
    }

    /**
     * 增加SpecParam
     * @param specParam
     */
    @Override
    public void add(SpecParam specParam){
        specParamMapper.insert(specParam);
    }

    /**
     * 根据ID查询SpecParam
     * @param id
     * @return
     */
    @Override
    public SpecParam findById(Integer id){
        return  specParamMapper.selectById(id);
    }

    /**
     * 根据分组名称查询SpecParam所有名称集合
     * @param groupName
     * @return
     */
    @Override
    public List<SpecParam> findAllByGroupName(String groupName) {
//        QueryWrapper<SpecParam> queryWrapper = new QueryWrapper<SpecParam>();
        // 设置查询字段和查询条件
//        queryWrapper.select("name").eq("group_id",groupId);
        SpecParam specParam = new SpecParam();
        specParam.setGroupName(groupName);
        return findList(specParam);
    }

    /**
     * 根据分组名称查询SpecParam通用名称集合
     * @param groupName
     * @return
     */
    @Override
    public List<SpecParam> findGeneralByGroupName(String groupName) {
//        QueryWrapper<SpecParam> queryWrapper = new QueryWrapper<SpecParam>();
        // 设置查询字段和查询条件
//        queryWrapper.select("name").eq("group_id",groupId);
        SpecParam specParam = new SpecParam();
        specParam.setGroupName(groupName);
        specParam.setIsGeneral(1);
        return findList(specParam);
    }

    /**
     * 根据分组名称查询SpecParam非通用名称集合
     * @param groupName
     * @return
     */
    @Override
    public List<SpecParam> findUnGeneralByGroupName(String groupName) {
        SpecParam specParam = new SpecParam();
        specParam.setGroupName(groupName);
        specParam.setIsGeneral(0);
        return findList(specParam);
    }

    /**
     * 查询全部SpecParam数据
     * @return
     */
    @Override
    public List<SpecParam> findAll() {
        return specParamMapper.selectList(null);
    }
}
